import request from '@/config/axios'

export interface DictVO {
  id?: number
  label: string
  parentId?: number
  status?: number
  sort?: number
  leaderUserId?: number
  phone?: string
  email?: string
  createTime?: Date
  children?: DictVO[]
}

// 查询字典（精简)列表
export const getSimpleDictList = async (): Promise<DictVO[]> => {
  return await request.get({ url: '/system/dict-data-ext/simple-list' })
}

// 查询字典列表
export const getDictPage = async (params: PageParam) => {
  return await request.get({ url: '/system/dict-data-ext/list', params })
}
// 查询字典列表
export const getDictChildren = async (params: { parentId: number }) => {
  return await request.get({ url: '/system/dict-data-ext/children', params })
}
// 根据字典值递归查询所有子节点
export const getDictChildrenByParentId = async (params: { parentId: number }) => {
  return await request.get({ url: '/system/dict-data-ext/children-by-parent-id', params })
}

// 查询字典详情
export const getDict = async (id: number) => {
  return await request.get({ url: '/system/dict-data-ext/get?id=' + id })
}

// 新增字典
export const createDict = async (data: DictVO) => {
  return await request.post({ url: '/system/dict-data-ext/create', data: data })
}

// 修改字典
export const updateDict = async (params: DictVO) => {
  return await request.put({ url: '/system/dict-data-ext/update', data: params })
}

// 删除字典
export const deleteDict = async (id: number) => {
  return await request.delete({ url: '/system/dict-data-ext/delete?id=' + id })
}
